package com.flydog.taskManager.controller;

import com.flydog.taskManager.common.api.CommonResult;
import com.flydog.taskManager.dto.TaskBriefParam;
import com.flydog.taskManager.entity.PeriodicTask;
import com.flydog.taskManager.entity.TaskBrief;
import com.flydog.taskManager.service.TaskBriefService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/taskBrief")
public class TaskBriefController {
    @Autowired
    TaskBriefService taskBriefService;

    @GetMapping("/listByPhaseTaskId/{id}")
    CommonResult<List<TaskBrief>> listByPhaseTaskId(@PathVariable("id") Long taskId) {
        return CommonResult.success(taskBriefService.listByPhaseTaskId(taskId));
    }


    @GetMapping("listByPeriodicTaskId/{id}")
    CommonResult<List<TaskBrief>> listByPeriodicTaskId(@PathVariable("id") Long taskId) {
        return CommonResult.success(taskBriefService.listByPeriodicTaskId(taskId));
    }


    @PostMapping("/create")
    CommonResult<TaskBrief> create(@RequestBody @Validated TaskBriefParam param) {
        return CommonResult.success(taskBriefService.create(param));
    }

    @PostMapping("/delete")
    CommonResult<List<TaskBrief>> delete(@RequestParam @NotEmpty Long[] ids) {
        return CommonResult.success(taskBriefService.delete(ids));
    }

    @PostMapping("/update/{id}")
    CommonResult<TaskBrief> update(@PathVariable("id") Long id, @RequestBody @Validated TaskBriefParam param) {
        return CommonResult.success(taskBriefService.update(id, param));
    }


}
